/***************************************************
> Copyright (C) 2024 ==KINGYI== All rights reserved.
> File Name: 1.c
> Author:cjy
> Mail: 
> Created Time: 2024年08月03日 星期六 11时11分08秒
***************************************************/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
int main(int argc,const char* argv[])
{
	pid_t pid = 0;
	int i = 0;
	time_t t;
	struct tm *nowtime;
	pid = fork();
	if(pid == 0) // zi
	{
		while(i < 5)
		{
			printf("child1 procee:%d\n",getpid());
			time(&t);
			nowtime = localtime(&t);
			printf("%02d:%02d:%02d\n", nowtime->tm_hour, nowtime->tm_min,nowtime->tm_sec);
			sleep(1);
			i++;
		}exit(0);
	}else if(pid < 0)
	{
		printf("fork error\n");
	}
	

	pid = fork();
	if(pid == 0)
	{
		while(i < 5)
		{
			printf("child2 procee:%d\n",getpid());
			time(&t);
			nowtime = localtime(&t);
			printf("%04d-%02d-%02d\n", nowtime->tm_year + 1900, nowtime->tm_mon + 1, nowtime->tm_mday);
			sleep(1);
			i = i + 1;
		}
		exit(0);

	}else if(pid > 0)
	{
	  while(i < 5)
	  {
		printf("father process:%d\n",getpid());
		sleep(1);
		i = i + 1;
	  }


	}else
	{
		printf("fork error\n");
	}
return 0;
}
